package com.owen.java.demo.datax;

import com.alibaba.datax.core.Engine;

public class Datax {

    public static String getCurrentClasspath(){
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        String currentClasspath = classLoader.getResource("").getPath();
        // 当前操作系统
        String osName = System.getProperty("os.name");
        if (osName.startsWith("Win")) {
            // 删除path中最前面的/
            currentClasspath = currentClasspath.substring(1, currentClasspath.length()-1);
        }
        return currentClasspath;
    }

    public static void main(String[] args) {

        // 注意：填写你解压缩datax的路径！！！
        System.setProperty("datax.home","D:\\soft\\datax\\datax");

        String[] datxArgs2 = {"-job", getCurrentClasspath()+"/datax/job.json", "-mode", "standalone", "-jobid", "-1"};

        try {
            Engine.entry(datxArgs2);
        } catch (Throwable e) {
            e.printStackTrace();
        }

    }

}
